package com.zxh.spDemo.service.impl;

import com.github.pagehelper.PageHelper;
import com.zxh.spDemo.dao.PermissionDao;
import com.zxh.spDemo.domain.Permission;
import com.zxh.spDemo.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(propagation=Propagation.REQUIRED,isolation=Isolation.DEFAULT,timeout=5)
@Service
public class PermissionServiceImpl implements PermissionService {

	@Autowired
	PermissionDao permissionDao;
	
	public Permission createPermission(Permission permission) {
		permissionDao.addpermission(permission);
		return permission;
	}

	public void deletePermission(Long permissionId) {
		permissionDao.deletepermission(permissionId);
	}

	public List<Permission> getPermissions() {
		return permissionDao.getPermissions();
	}

	public Permission getPermissionByid(Long permissionid) {
		return permissionDao.getPermissionByid(permissionid);
	}

	public Permission updatePermission(Permission permission) {
		permissionDao.updatePermission(permission);
		return permission;
	}

	public List<Permission> getPagePermissions(int pagenum, int pagesize) {
		PageHelper.startPage(pagenum,pagesize);
		List<Permission> list=permissionDao.getPermissions();
		return list;
	}

	public void deletePermissions(Long permissionId) {
		permissionDao.deletePermissionsByid(permissionId);
	}

}
